package com.xdf.zipperdye.controller;

import com.xdf.zipperdye.model.Contact;
import com.xdf.zipperdye.service.ContactService;
import com.xdf.zipperdye.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(description = "客户")
@CrossOrigin
@RestController
@RequestMapping("contact")
public class ContactController {
    @Autowired
    private ContactService service;

    @ApiOperation(value="根据主键删除客户", notes="根据主键删除客户。返回 Integer", produces="application/json")
    @ApiImplicitParam(name = "iid", value = "客户表主键", paramType = "query", required = true, dataType = "Integer")
    @GetMapping("/deleteByPrimaryKey/{iid}")
    public JsonResult deleteByPrimaryKey(@PathVariable Integer iid){
        return JsonResult.ok(service.deleteByPrimaryKey(iid));
    }

    @ApiOperation(value="新增客户", notes="新增客户。返回 Integer", produces="application/json")
    @PostMapping("/insert")
    public JsonResult insert(@RequestBody Contact record){
        return JsonResult.ok(service.insert(record));
    }

    @ApiOperation(value="选择性新增客户", notes="选择性新增客户。返回 Integer", produces="application/json")
    @PostMapping("/insertSelective")
    public JsonResult insertSelective(@RequestBody Contact record){
        return JsonResult.ok(service.insertSelective(record));
    }

    @ApiOperation(value="根据主键查询获取客户", notes="根据主键查询获取客户。返回模型同新增的传入参数", produces="application/json")
    @GetMapping("/selectByPrimaryKey/{iid}")
    public JsonResult selectByPrimaryKey(@PathVariable Integer iid){
        return JsonResult.ok(service.selectByPrimaryKey(iid));
    }

    @ApiOperation(value="选择性修改客户", notes="选择性修改客户。传入参数同新增的传入参数", produces="application/json")
    @PostMapping("/updateByPrimaryKeySelective")
    public JsonResult updateByPrimaryKeySelective(@RequestBody Contact record){
        return JsonResult.ok(service.updateByPrimaryKeySelective(record));
    }

    @ApiOperation(value="完全修改客户", notes="完全修改客户。传入参数同新增的传入参数", produces="application/json")
    @PostMapping("/updateByPrimaryKey")
    public JsonResult updateByPrimaryKey(@RequestBody Contact record){
        return JsonResult.ok(service.updateByPrimaryKey(record));
    }

    @ApiOperation(value="获取所有客户", notes="获取所有客户。没有传入参数，返回数组", produces="application/json")
    @GetMapping("/selectAll")
    public JsonResult selectAll(){
        return JsonResult.ok(service.selectAll());
    }

    @ApiOperation(value="根据客户编号查询获取客户", notes="根据客户编号查询获取客户。传入参数是客户编号", produces="application/json")
    @GetMapping("/selectBySid/{sid}")
    public JsonResult selectBySid(@PathVariable String sid){
        return JsonResult.ok(service.selectBySid(sid));
    }
}
